<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>缴费管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"> 类 型</label>
                            <div class="layui-input-inline">
                                <select lay-search="" name="type">
                                    <option value="">请选择</option>
                                    <option value="1">已缴纳</option>
                                    <option value="0">未缴纳</option>
                                </select>
                            </div>


                        </div>
                    </div>

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                        </button>
                    </div>

                </form>
            </div>
        </fieldset>

        <%--工具栏--%>
        <script type="text/html" id="toolbarDemo"> </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">确认缴费</a>
        </script>

    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/costServlet?opt=cy2',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [[ // 表格列
                {field: 'id', title: 'ID', sort: true},
                {field: 'name', title: '缴费名'},
                {field: 'username', title: '业主'},

                {field: 'value', title: '缴费金额', sort: true},
                {field: 'time', title: '缴费时间', sort: true},
                {
                    field: 'status', title: '状态', templet: function (d) {
                        if (d.status === 1) {
                            return '<input type="checkbox" lay-text="已缴费|未缴费" lay-skin="switch" checked disabled>'
                        } else if (d.status === 0) {
                            return '<input type="checkbox" lay-text="已缴费|未缴费" lay-skin="switch" disabled>'
                        }
                    }
                },


                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [2, 4, 6, 8, 10], // 每页显示的条数
            limit: 10,  // 当前页
            page: true, // 开启分页
            skin: 'line' // 默认皮肤
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    type: data.field.type
                }
            }, 'data');

            return false;
        });


        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') {

                if (data.status == 0) {
                    $.get('/costServlet?opt=id&id=' + data.id, data, function (data) {
                            if (data.code == 0) {
                                layer.msg(data.msg, {
                                    icon: 1,
                                    anim: 0,//取消抖动
                                    time: 1000
                                }, function () {
                                    window.location = '/page/admin/costMge.jsp';
                                });
                            } else {
                                layer.msg(data.msg, {icon: 2})
                            }
                        },"json"
                    )
                }
            }
        });


    })
    ;
</script>

</body>
</html>